<?php
namespace app\api\controller;
use app\common\controller\ApiBase;
use think\Request;
use think\Controller;
// 引入AipSpeech.php
use baidu\AipSpeech;

class Bdvoice extends ApiBase{
    
    protected $app_id;
    protected $app_key;
    protected $secret_key;
    protected $client;
    

    protected function _initialize()
    {
        parent::_initialize();
        /*
         * 百度voice识别appkey
         * */
        $this->app_id = '0000'; // 换成申请到的appid
        $this->app_key = 'asdfg'; // 换成申请到的app_key
        $this->secret_key = 'asdf'; // 换成申请到的secret_key
        $this->client = new AipSpeech($this->app_id, $this->app_key, $this->secret_key);
        
    }

    public function index(){
    	//  file_put_contents('./requestMsg.log','query_auth_code:'.$query_auth_code."\n",FILE_APPEND);
    	// 识别本地文件
		$result = $this->client->asr(file_get_contents('./bj.amr'), 'amr', 16000, array('dev_pid' => 1536,));
		return json_encode($result,JSON_UNESCAPED_UNICODE);
    }

    public function testpcm(){
        $result = $this->client->asr(file_get_contents('./test.pcm'), 'pcm', 16000, array('dev_pid' => 1536,));
        return json_encode($result,JSON_UNESCAPED_UNICODE);
    }

}